package hu;

class TestTicketRunnable{
    public static void main(String[] a){
        TicketThread tThread = new TicketThread();
        new Thread(tThread).start();
        new Thread(tThread).start();
        new Thread(tThread).start();
    }
}

class TicketThread implements Runnable {
    private int ticket = 5;
    public void run(){
        for (int i = 0; i < 5; i++){
            synchronized(this){
                if (ticket > 0){
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "卖票：ticket = " + ticket--);
                }
            }
        }
    }
}
